local skel = fk.CreateSkill {
  name = "rmt__fuxing",
}

Fk:loadTranslationTable{
  ["rmt__fuxing"] = "馥行",
  [":rmt__fuxing"] = "每轮限一次，其他角色的弃牌阶段结束时，你可展示手牌，若与其弃置牌无同名牌，你可获得其中点数最小的牌。",
}

skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "drawcard",
  times = function (_, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryRound)
  end,
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(skel.name) and target.phase == Player.Discard
    and player:usedSkillTimes(skel.name, Player.HistoryRound) == 0 then
      local room = player.room
      local discards, cards = {}, {}
      local phase_event = room.logic:getCurrentEvent():findParent(GameEvent.Phase, true)
      if phase_event == nil then return false end
      local end_id = phase_event.id
      room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if not table.contains(cards, id) then
              table.insert(cards, id)
              if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and
                room:getCardArea(id) == Card.DiscardPile then
                if move.from == target and info.fromArea == Card.PlayerHand then
                  table.insert(discards, id)
                end
              end
            end
          end
        end
        return false
      end, end_id)
      if #discards >= 0 then
        event:setCostData(self, discards)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local hand = table.simpleClone(player.player_cards[Player.Hand])
    local discards = event:getCostData(self)
    if not player:isKongcheng() then
      player:showCards(player:getCardIds("h"))
    end
    if #discards == 0 or player.dead then return end
    local get = true
    for _, id in ipairs (hand) do
      if table.find(discards, function(p) return Fk:getCardById(id).trueName == Fk:getCardById(p).trueName end) then
        get = false
        break
      end
    end
    if get and not player.dead then
      local min = 13
      for _, id in ipairs(discards) do
        if Fk:getCardById(id).number < min then
          min = Fk:getCardById(id).number
        end
      end
      local getlist = table.filter(discards, function (id)
        return Fk:getCardById(id).number == min
      end)
      player.room:obtainCard(player, getlist, true, fk.ReasonPrey, player, skel.name)
    end
  end,
})



return skel
